<%=javascript_include_tag "work_time", :plugin=>'redmine_work_time' %>
<script type="text/javascript">
<!--
var add_ticket_count = 1;
function add_ticket(pop_url, ajax_url)
{
  var tickets = showModalDialog(pop_url, window, "dialogWidth:600px;dialogHeight:480px");
  for(i=0; i<tickets.length;i++) {
      new Ajax.Updater('time_input_table_bottom', ajax_url+"&add_issue="+tickets[i]+"&count="+add_ticket_count, {insertion:Insertion.Before, method:'get'});
      add_ticket_count ++;
  }
}

function dup_ticket(ajax_url, insert_pos, id)
{
    new Ajax.Updater( insert_pos, ajax_url+"&add_issue="+id+"&count="+add_ticket_count, {insertion:Insertion.After, method:'get'});
      add_ticket_count ++;
}
-->
</script>

<%= @message %>
<div style="text-align:right;">
<%= render :partial=>'select_project' %><br/>
<%if User.current.allowed_to?(:view_work_time_other_member, @project) then%>
  <%= link_to(l(:wt_relay_total), @link_params.merge(:action=>"relay_total")) %>
  <%= render :partial=>'select_user', :locals=>{:link_params=>@link_params} %><br/>
<%end%>
<%if @project && User.current.allowed_to?(:edit_work_time_total, @project) then%>
  <%if WtHolidays.find(:all, :conditions=>["holiday=:h and deleted_on is null",{:h=>@this_date}]).size == 0 then %>
    <%= link_to(l(:wt_set_holiday), @link_params.merge(:set_holiday=>@this_date)) %>
  <%else%>
    <%= link_to(l(:wt_del_holiday), @link_params.merge(:del_holiday=>@this_date)) %>
  <%end%>
<%end%>
</div>

<h2><%=l(:wt_monthly_report)%> (<%=@this_user%>)</h2>
<%= render :partial=>'user_month_table' %>

<br/>

<h2>
  <%=l(:wt_daily_report)%>
</h2>
<% form_tag @link_params do %>
<%= hidden_field_tag('year', @this_year) %>
<%= hidden_field_tag('month', @this_month) %>
<%= hidden_field_tag('day', @this_day) %>
<%= hidden_field_tag('user', @this_uid) %>
<%= hidden_field_tag('prj', @restrict_project) %>

<%= render :partial=>'user_day_table' %>

<%if @this_uid==@crnt_uid then%>
[<a href="JavaScript:add_ticket('<%=url_for(:action=>"popup_select_tickets")%>',
                                '<%=url_for(@link_params.merge(:action=>"ajax_insert_daily"))%>');"
>
  <%=l(:wt_add_ticket)%>
</a>]
[<%= link_to(l(:wt_delete_closed_tickets), @link_params.merge(:ticket_del=>"closed")) %>]
<%= submit_tag l(:wt_update) %>
<br/>
<%end%>

<br/>
<h2 id="memo">
  <%=link_to(@this_year.to_s+'/'+@this_month.to_s+'/'+@this_day.to_s+
    '('+@wday_name[@this_date.wday]+') '+@this_user.to_s,
    @link_params.merge(:anchor=>"memo"))
  %>
</h2>

<%#------------------------------------------- Wiki表示#%>
<div id="memo-wiki">
<%
memo=WtDailyMemo.find(:first, :conditions=>["day=:d and user_id=:u",{:d=>@this_date,:u=>@this_uid}])
if memo then # この日のメモがある場合
%>
<div class="wiki" style="background:#ffb;">
  <%=textilizable(memo.description) %>
  <div style="text-align:right;">
    (update:<%=memo.updated_on.strftime("%y/%m/%d %H:%M")%>)
  </div>
</div>
<%end%>

<%
memo=WtDailyMemo.find(:first, :order=>"day DESC", :conditions=>["day<:d and user_id=:u",{:d=>@this_date,:u=>@this_uid}])
if memo then
d = memo.day
%>
[<%=link_to(l(:wt_pre_memo), @link_params.merge(:anchor=>"memo", :day=>d.day, :month=>d.month, :year=>d.year))%>]
<%end%>

<%if @this_uid==@crnt_uid then%>
[<a href="#" onclick="JavaScript:new Ajax.Updater('memo-wiki',
  '<%=url_for(@link_params.merge(:action=>"ajax_memo_edit"))%>',
  {asynchronous:true, method:'get'}); return false;">
  <%=l(:wt_edit_memo)%>
</a>]
<%end%>

<%
memo=WtDailyMemo.find(:first, :order=>"day", :conditions=>["day>:d and user_id=:u",{:d=>@this_date,:u=>@this_uid}])
if memo then
d = memo.day
%>
[<%= link_to(l(:wt_next_memo), @link_params.merge(:anchor=>"memo", :day=>d.day, :month=>d.month, :year=>d.year))%>]
<%end%>
</div>
<br/>

<%if User.current.allowed_to?(:view_work_time_other_member, @project) then%>
  <%= render :partial=>'select_user', :locals=>{:link_params=>@link_params.merge(:anchor=>"memo")} %>
<%end%>

<%end%>

